#include "fwPlatformContext.h"
#include "fwWindows.h"
#include "..\fwLog.h"
#include "..\fwMessageService.h"

//======================================PLAFORMCONTEXT===============================/
PlatformContext::PlatformContext()
:m_szTitle(NULL), m_iFlags(0)
{
	LOGIDBG("Init PlatformContext\n");
}

PlatformContext::~PlatformContext()
{
	LOGIDBG("Destroy PlatformContext\n");
}

void PlatformContext::Exit()
{}

//======================================WINDOWS===============================/

Windows * Windows::m_pInstance = NULL;

Windows::Windows()
:PlatformContext()
{
	LOGIDBG("Init WindowsContext\n");
	m_pInstance = this;
}

Windows::~Windows()
{
	LOGIDBG("Destroy WindowsContext\n");
}

void Windows::Destroy()
{
	
	SAFE_DEL(m_pInstance);
}

LRESULT Windows::WinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
	LRESULT  lRet = 1;
	KeyBoard keyboard;

	switch (msg)
	{
	case WM_CREATE:
		break;
	case WM_PAINT:
		//Pant event
		//Draw function
		ValidateRect(hWnd, NULL);
		break;
	case WM_DESTROY:
		PostQuitMessage(0);
		break;
	case WM_KEYDOWN:
		//m_pInstance->KeyboardUpdate(wParam, true);
		keyboard;
		keyboard.key = wParam;
		keyboard.status = true;
		MessageService::GetInstance()->SendMessageTag(NULL, "KEYBOARD_EVENT", (FWobject)&keyboard);
		break;
	case WM_KEYUP:
		//m_pInstance->KeyboardUpdate(wParam, false);
		keyboard;
		keyboard.key = wParam;
		keyboard.status = false;
		MessageService::GetInstance()->SendMessageTag(NULL, "KEYBOARD_EVENT", (FWobject)&keyboard);
		break;
	default:
		lRet = DefWindowProc(hWnd, msg, wParam, lParam);
		break;
	}

	return lRet;
}